package com.cqq.boot.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.annotations.ApiIgnore;

import com.cqq.boot.base.BaseController;
import com.cqq.boot.domain.Hotel;
import com.cqq.boot.domain.User;
import com.cqq.boot.service.HotelService;
import com.cqq.boot.service.UserService;
import com.github.pagehelper.Page;

@RestController
@RequestMapping("/test")
@Api("测试相关api")
public class TestController extends BaseController{

	@Autowired
    private UserService userService;
	@Autowired
	private HotelService hotelService;
	
	@GetMapping("/helloworld")
    public String helloworld() {
        return "helloworld23";
    }
	
	@ApiOperation(httpMethod = "GET", value = "根据用户id获取用户信息", notes="获取用户信息")
	@ApiImplicitParams(value={
        @ApiImplicitParam(name="id",dataType="Integer",paramType="path",required=true,value="用户id")
    })
	@ResponseBody
	@RequestMapping("/getUserById/{id}")
    public User getUserById(@ApiIgnore @PathVariable Integer id) {
        return userService.getUserById(id);
    }
	
	@ApiOperation(httpMethod = "GET", value = "获取用户信息列表", notes="获取用户信息")
	@ResponseBody
	@RequestMapping("/getUsers")
	public List<User> getUsers() {
		return userService.getUsers();
	}
	
	@ApiOperation(httpMethod = "POST", value = "添加用户信息", notes="添加用户信息")
	@ApiImplicitParams(value={
        @ApiImplicitParam(name="age",dataType="Integer",paramType="query",required=true,value="年龄"),
        @ApiImplicitParam(name="create",dataType="Integer",paramType="query",required=true,value="create"),
        @ApiImplicitParam(name="name",dataType="String",paramType="query",required=true,value="姓名")
    })
	@ResponseBody
	@RequestMapping("/add")
	public int add(@ApiIgnore Integer age, @ApiIgnore Integer create, @ApiIgnore String name) {
		User user = new User();
		user.setAge(age);
		user.setCreate(create);
		user.setName(name);
		return userService.add(user);
	}
	
	@ApiOperation(httpMethod = "POST", value = "添加酒店信息", notes="添加酒店信息")
	@ApiImplicitParams(value={
        @ApiImplicitParam(name="address",dataType="String",paramType="query",required=true,value="地址"),
        @ApiImplicitParam(name="city",dataType="Integer",paramType="query",required=true,value="city"),
        @ApiImplicitParam(name="name",dataType="String",paramType="query",required=true,value="酒店名称"),
        @ApiImplicitParam(name="zip",dataType="String",paramType="query",required=true,value="邮编")
    })
	@ResponseBody
	@RequestMapping("/addHotel")
	public int addHotel(@ApiIgnore String address, @ApiIgnore Integer city, @ApiIgnore String name, @ApiIgnore String zip) {
		Hotel hotel = new Hotel();
		hotel.setAddress(address);
		hotel.setCity(city);
		hotel.setName(name);
		hotel.setZip(zip);
		return hotelService.add(hotel);
	}
	
	@ApiOperation(httpMethod = "GET", value = "查询酒店信息列表", notes="查询酒店信息")
	@ResponseBody
	@RequestMapping("/getHotels")
	public List<Hotel> getHotels() {
		return hotelService.queryHotels();
	}
	
	
	@ApiOperation(httpMethod = "GET", value = "分页查询酒店信息", notes="查询酒店信息")
	@ApiImplicitParams({
        @ApiImplicitParam(name="pageNo",dataType="Integer",paramType="path",required=true,value="分页NO")
    })
	@ResponseBody
	@RequestMapping("/queryPageHotel/{pageNo}")
    public Page<Hotel> queryPageHotel(@PathVariable Integer pageNo) {
        return hotelService.queryPage(pageNo, 1);
    }
	
}
